package com.suse.result;

import lombok.Data;

import static com.suse.result.ResultEnum.*;

/**
 * 响应结果类
 */
@Data
public class Result {

    private boolean success;

    private String message;

    private Object data;

    private static Result build(ResultEnum resultEnum) {
        Result result = new Result();
        result.setSuccess(resultEnum.isSuccess());
        result.setMessage(resultEnum.getMessage());
        return result;
    }

    /**
     * 操作成功
     */
    public static Result success(){
        return build(RESULT_OPERATION_SUCCESS);
    }

    public static Result success(ResultEnum resultEnum){
        return build(resultEnum);
    }

    public static Result success(Object data){
        Result result = success();
        result.setData(data);
        return result;
    }

    /**
     * 操作失败
     */
    public static Result error(){
        return build(RESULT_OPERATION_FAIL);
    }

    public static Result error(ResultEnum resultEnum){
        return build(resultEnum);
    }



}
